package com.woniuxy02;

import java.util.Scanner;

public class Test02 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        //系统随机数
        int random;
        int num;
        int count=1;
        //true猜对了，false猜错了
        boolean flag;
        String answer="";
        do {
            //每次开始一局游戏，变量归零(初始化)
            random = (int) (Math.random() * 100);
            count=1;
            flag=false;
            System.out.println("random:"+random);
            do{

                System.out.println("输入你猜的数字");
                num=scanner.nextInt();
                if(num>random){
                    System.out.println("猜大了");
                }else if(num<random){
                    System.out.println("猜小了");
                }else{
                    System.out.println("猜对了");
                    flag=true;
                    break;
                }

                if (count<5) {
                    System.out.println("还有"+(5-count)+"次几乎");
                }
                count++;
            }while (count<=5);
            //猜对了，游戏结束
            //次机会用完了，游戏结束
            if (flag) {
                System.out.println("猜对了游戏结束，结束");
            } else {
                System.out.println("5次机会用完了，游戏结束");
            }
            System.out.println("是否继续y/n");
            answer=scanner.next();
        } while (answer.equals("y"));
    }
}
